package quickcore.push.xmpush;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;

import com.xiaomi.mipush.sdk.MiPushClient;

import quickcore.push.PushWrap;

public class XMPushWrap implements PushWrap{
    private Context context;
    public XMPushWrap(Context context){
        this.context = context;
    }
    @Override
    public void init() {
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo appInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            String appid = appInfo.metaData.getString("XMPUSH_APPID");
            String appkey = appInfo.metaData.getString("XMPUSH_APPKEY");
            if(appid!=null&&appkey!=null){
                String id = appid.replace("\\","");
                String key = appkey.replace("\\","");
                MiPushClient.registerPush(context,id,key);
            }

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void setAlias(String alias) {
        MiPushClient.setAlias(context,alias,null);
    }
}
